package com.mc.music_web.controller;


import com.github.pagehelper.PageInfo;
import com.mc.music_web.entity.Singer;
import com.mc.music_web.services.SingerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class SingerController {

    @Autowired
    private SingerService singerService;

    @RequestMapping("/admin/lastSinger")
    public  String goSinger(){

        return "/admin/singer";
    }

    @RequestMapping("/admin/singerList")
    @ResponseBody
    public List singerList(){
        List<Singer> list=singerService.selectAllListSinger();
        return list;
    }

    @RequestMapping("/admin/goSingerUpdate")
    @ResponseBody
    public Singer updateSinger(Integer singerId) {

        Singer singer = singerService.selectByPrimaryKeySinger(singerId);

        return singer;
    }


    @RequestMapping("/admin/doSingerUpdate")
    @ResponseBody
    public Singer doUpdateSinger(Singer singer) {

        singerService.updateByPrimaryKeySinger(singer);
        return singer;
    }


    @RequestMapping("/admin/goSingerLimit")
    @ResponseBody
    public PageInfo selectSingerLimit(int pageNum, HttpSession session) {
        PageInfo<Singer> pageInfos = singerService.selectSingerLimit(pageNum);
        session.setAttribute("singerSession",pageInfos);
        return pageInfos;
    }


    @RequestMapping("/admin/singDel")
    @ResponseBody
    public int del(Integer singerId) {
        int result = singerService.delteSinger(singerId);

        return result;
    }

    @RequestMapping("/admin/addSinger")
    public String addSinger(){

        return "/admin/add";
    }

    @RequestMapping("/admin/addSingers")
    @ResponseBody
    public Integer addSinger(Singer singer){

        Integer i = singerService.insert(singer);
        return i;
    }
    @RequestMapping("/admin/adminBySinger")
    @ResponseBody
    public  List  selectBySinger(String keyword){
        List<Singer> list=singerService.selectByChooseSinger(keyword);
        return list;
    }
}
